import { ArrayHelper } from "./ArrayHelper";

// type Callback<T> = (n: T, i: number) => boolean;
interface Callback<T> {
  (n: T, i: number): boolean;
}

function filter<T>(arr: T[], callback: Callback<T>) {
  const newArr: T[] = [];
  for (let i = 0; i < arr.length; i++) {
    if (callback(arr[i], i)) {
      newArr.push(arr[i]);
    }
  }

  return newArr;
}

console.log(filter(["1", "2", "3"], (n, i) => i % 2 === 0));

const helper = new ArrayHelper([1, 2, 3, 4, 2, 4, 5]);
helper.shuffle();
console.log(helper.take(4));
